package czolgisci.display;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;

import javax.swing.JPanel;

public class ImagePanel extends JPanel
{
	private static final long serialVersionUID = 1L;
	Image image;

	public void setImage(Image image)
	{
		this.image = image;
	}

	public void paintComponent(Graphics g)
	{
		if (image != null)
		{
			g.drawImage(image, 0, 0, this);
		}
	}

	public Dimension getPreferredSize()
	{
		int w, h;
		if (image == null)
		{
			return new Dimension(0, 0);
		}
		w = image.getWidth(null);
		h = image.getHeight(null);
		return new Dimension(w > 0 ? w : 0, h > 0 ? h : 0);
	}
}